/**
 * @author 马旭阳
 *
 */
public class Exam01 {
    public static void main(String[] args) {
        int[] aa = new int[]{1,2,3,4};
        int a=binarySort(aa,5);
        System.out.println(a);
    }
    private  static int binarySort(int[] aa,int val){
        int before = 0;
        int index = aa.length-1;
        while (index > before) {
            int mid = (index + before)/2;
            if (aa[mid] > val) {
                index = mid - 1;
            }else if (aa[mid] < val) {
                before = mid +1 ;
            }else {
                return mid;
            }
        }
        return -1;
    }
}
